package com.mobilepay.moneypig.utils;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.mobilepay.moneypig.R;

/**
 * Created by xlm on 2017/7/13 0013
 */

public class CountDownTimerUtils extends CountDownTimer {
    private TextView mTextViewForget;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mTextViewForget = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {

        mTextViewForget.setClickable(false);
        mTextViewForget.setText(millisUntilFinished / 1000 + "s");
        String mTextColor = "#e46641";
        mTextViewForget.setTextColor(Color.parseColor(mTextColor));
    }

    @Override
    public void onFinish() {
        mTextViewForget.setClickable(true);//重新获得点击
        mTextViewForget.setText("获取验证码");
        mTextViewForget.setBackgroundResource(R.drawable.selector_regist_code);  //还原背景色
    }
}
